﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLChoDiaOc.Process;

namespace QLChoDiaOc.Forms
{
    /// <summary>
    /// Interaction logic for WinThemNhanVien.xaml
    /// </summary>
    public partial class WinThemNhanVien : Window
    {
        GetID _getID = new GetID();
        InsertInfo _inserInfo = new InsertInfo();
        SelectInfo _selectInfo = new SelectInfo();

        public WinThemNhanVien()
        {
            InitializeComponent();
            maNhanVientextbox.Text = _getID.GenerateMaNhanVien();
            AddComboBox();
        }

        void AddComboBox()
        {
            loaiNhanVienComboBox.Items.Clear();
            for (int i = 0; i < _selectInfo.SelectAllTenLoaiNH().Count; i++)
                loaiNhanVienComboBox.Items.Add(_selectInfo.SelectAllTenLoaiNH()[i]);
        }

        private void btnThemNhanVienWin_Click(object sender, RoutedEventArgs e)
        {
            if (hoTenTextBox.Text == "" || loaiNhanVienComboBox.SelectedItem == null)
                MessageBox.Show("Chưa điền đầy đủ thông tin", "Thông Báo");
            else
            {
                try
                {
                    _inserInfo.InsertNhanVien(maNhanVientextbox.Text, hoTenTextBox.Text, _selectInfo.SelectMaLoaiNhanVien(loaiNhanVienComboBox.SelectedItem.ToString()));
                    _inserInfo.InsertDangNhapKhachHang(maNhanVientextbox.Text);
                    btnThemNhanVienWin.IsEnabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Thông Báo");
                }
            }
        }

        private void btnThoatNhanVienWin_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
